package douyubishi;

import java.util.Scanner;

/**
 * Created by JiaJia on 2019/8/27 0027.
 */
public class Test {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            int n=scanner.nextInt();
            int total=scanner.nextInt();
            int cost=scanner.nextInt();
            int[] arr1=new int[n];
            int[] arr2=new int[n];
            for (int i = 0; i <n ; i++) {
                arr1[i]=scanner.nextInt();
            }
            for (int i = 0; i <n ; i++) {
                arr2[i]=scanner.nextInt();
            }
            System.out.println(diamond(arr1,arr2,n,total,cost));
        }
        scanner.close();
    }
    private static int diamond(int[] arr1,int[] arr2,int n,int total,int cost){
        int pay=0;
        int baoshi=0;
        int p1=0,p2=0;
        while (p1<n&&p2<n&&pay<=total){
            if (arr1[p1]==arr2[p2]){
                baoshi+=1;
                pay+=cost;
                p1++;
                p2++;
            }
            p1++;
        }
        return baoshi;

    }
}